<template>
  <div class="login-container" :style="{background:$store.getters.theme,'--themeColor':theme,'--textColor':TopTextColor,'--lightOpacity':lightTheme}">
    <div class="bglogin">
      <div class="bglogin-title">{{ platformName }}</div>
      <div class="bglogin-layout">
        <div class="img-box">
          <img src="../../assets/login-illustration.png" draggable="false">
        </div>
        <div class="form-container" :class="{'mobile-form-container': device === 'mobile'}">
          <AuthenticationFactorOne
            v-if="tenantId"
            :config-data="configD"
            :active-type="authType"
            :tenant-id="tenantId"
          />
        </div>
        <!-- <div class="form-container reset-container" :class="{'mobile-form-container': device === 'mobile'}" v-else>
          <resetPassword @backLogin="loginState = true" />
        </div> -->
      </div>
    </div>
  </div>
</template>
<script>
import ResizeMixin from '@/framework/layout/mixin/ResizeHandler'
import { getCookie } from '@/framework/utils/auth'
import { mapGetters } from 'vuex'
import AuthenticationFactorOne from './components/AuthenticationFactorOne'
import { getTenantDropDownList, getAuthRules } from '@/framework/api/user'
// import resetPassword from './components/resetPassword'

export default {
  name: 'dtLogin',
  components: {
    AuthenticationFactorOne
    // resetPassword
  },
  mixins: [ResizeMixin],
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入用户名'))
      } else if (value.length <= 0) {
        callback(new Error('请输入用户名'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入密码'))
      } else {
        callback()
      }
    }
    return {
      dialogTitle: '滑块验证',
      dialogFormVisible: false,
      miniimgurl: '',
      imgurl: '',
      logintypFlag: false,
      slideVerifyWidth: 432,
      blockW: 60,
      block_y: 0,
      text: '测试',
      isRbPw: false,
      loginForm: {
        tenantId: '000000',
        account: '',
        password: ''
      },
      tenantId: '',
      loginRules: {
        tenantId: [{ required: true, trigger: 'change', message: '请选择租户' }],
        account: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined,
      selectList: [],
      authType: 'zhangmi',
      configD: {},
      loginState: true
    }
  },
  computed: {
    ...mapGetters([
      'device'
    ]),
    platformName() {
      return this.$store.state.settings.platformName
    },
    footerText() {
      return this.$store.state.settings.footerText
    },
    platformLogo() {
      return this.$store.state.settings.platformLogo
    },
    sidebarThemeColor() {
      return this.$store.getters.sidebarThemeColor
    },
    theme() {
      return this.$store.getters.theme
    },
    TopTextColor() {
      return this.$store.getters.TopTextColor
    },
    lightTheme() {
      return `${this.theme}19`
    }
  },
  watch: {
    $route: {
      handler(route) {
        if (route.query.ssoLoginFlag == 'true') {
          this.logintypFlag = true
        } else {
          this.logintypFlag = false
        }
        // this.redirect = route.query && route.query.redirect
        this.redirect = '/'
      },
      immediate: true
    }
  },
  created() {
  },
  mounted() {
    this.getSelect()
    this.initData()
  },
  methods: {
    handleHelpClick() {
      window.open(process.env.VUE_APP_DEV_DOC)
    },
    async initData() {
      const { username, password, checked } = getCookie()
      this.loginForm.account = username
      this.loginForm.password = password
      this.isRbPw = checked
      // 处理适配
      if (this.$store.getters.device === 'mobile') {
        this.slideVerifyWidth = 300
        this.blockW = 42
      } else {
        this.slideVerifyWidth = 432
        this.blockW = 60
      }
    },
    // 忘记密码
    goforgetpw() {
      this.$router.push({
        path: '/newForgetPw'
      })
    },
    // 获取租户下拉框
    getSelect() {
      getTenantDropDownList().then(async (res) => {
        this.selectList = res.data
        if (this.logintypFlag) {
          this.tenantId = this.$route.query.tenantId
        } else {
          this.tenantId = '000000'
        }

        await this.queryAuthRules()
      })
    },
    async queryAuthRules() {
      const { data } = await getAuthRules({ tenantId: this.tenantId })
      this.configD = data
    },
    tenantChange() {
      this.queryAuthRules()
    }

  }
}
</script>
  <style lang="scss">
  /* 修复input 背景不协调 和光标变色 */
  /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  $bg:#283443;
  $light_gray:#fff;
  $cursor: #fff;
  @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
    // .login-container .el-input input {
    //   // color: $cursor;
    // }
  }
  </style>
  <style lang="scss" scoped>
  $bg:#2d3a4b;
  $dark_gray:#889aa4;
  $light_gray:#eee;
  $cursor: #fff;
 .login-container {
    height: 100%;
    width: 100%;
    .bglogin{
      min-height: 100%;
      width: 100%;
      overflow: hidden;
      background: url("../../assets/login-bg.png") 0 0 no-repeat;
      background-size: cover;
      z-index: 999;
      .bglogin-title {
        font-family: SourceHanSansCN-Bold;
        font-weight: 700;
        font-size: 40px;
        height: 40px;
        line-height: 40px;
        color: #FFFFFF;
        text-align: center;
        margin-top: 7vh;
      }
      .bglogin-layout {
        margin-top: 48px;
        width: 100%;
        overflow: hidden;
        display: flex;
        // flex-direction: column;
        justify-content: center;
        align-content: center;
      }
      .img-box {
        margin-right: 9%;
        width: 535.41px;
        img {
          width: 100%;
        }
      }
    }
    .textbox{
      flex: 1;
      margin: 3% 9%;
      position: relative;
      .logowhite{
        width: 178px;
        height: 63px;
      }
      .bottomtext{
        position: absolute;
        bottom: 0;
        left: 0;
        font-family: PingFang SC-常规体, PingFang SC;
        font-weight: normal;
        color: #97A1B8;
        line-height: 14px;
        font-size:12px;
      }
      .contenttext{
      margin: 5% 0 2%;
      font-size: 18px;
      font-weight: 400;
      color: #FFFFFF;
      line-height: 36px;
    }
    .contenttext2{
      font-size: 16px;
      font-weight: 400;
      color: rgb(255,255,255,0.75);
      line-height: 22px;
      span:nth-of-type(2){
        margin:0 40px;
      }
    }

      .btnbox{
        width: 100px;
          font-size: 16px;
          font-family: PingFang SC-中黑体, PingFang SC;
          font-weight: normal;
          color: #FFFFFF;
          line-height: 19px;
          margin-top: 40px;
          display: flex;
          align-items: center;
          cursor: pointer;
        }
    }
    .form-container{
      position: relative;
      width: 400px;
      height: 410px;
      padding: 92px 36px 60px;
      background: #fff;
      box-shadow: 0px 4px 32px 4px rgba(0,0,0,0.0200), 0px 16px 24px 2px rgba(0,0,0,0.0400), 0px 0px 12px 0px rgba(0,0,0,0.0800);
      border-radius: 8px;
      opacity: 1;
      align-self: center;
      // margin-right: 190px;
      box-sizing: border-box;
      &::before {
        content: "欢迎登录";
        display: block;
        position: absolute;
        width: 174px;
        height: 44px;
        top: -11px;
        left: 50%;
        transform: translate(-50%);
        font-family: SourceHanSansCN-Medium;
        font-weight: 500;
        font-size: 18px;
        color: #FFFFFF;
        text-align: center;
        line-height: 44px;
        background: url('../../assets/login-title-bg.png') no-repeat;
        background-size: cover;
      }
    }
    .reset-container {
      padding: 83px 36px 60px;
    }
    .mobile-form-container{
      margin: auto;
    }
    .login-form {
      position: relative;
      // width: 520px;
      max-width: 100%;
      // padding: 0px 35px 0;
      margin: 0 auto;
      overflow: hidden;
    }
    /* reset element-ui css */
    ::v-deep .el-input {
      display: inline-block;
      height: 40px;
      width: 100%;
      background: #FFFFFF;
      border-radius: 4px 4px 4px 4px;
      opacity: 1;
      // border: 1px solid #DCDFE6;
      input {
        height:40px;
        border: 1px solid #DCDFE6;
        // background: transparent;
        // border: 0px;
        // -webkit-appearance: none;
        // border-radius: 0px;
        // padding: 12px 5px 12px 15px;
        // color: $light_gray;
        // height: 47px;
        // caret-color: $cursor;
        // &:-webkit-autofill {
        //   box-shadow: 0 0 0px 1000px $bg inset !important;
        //   -webkit-text-fill-color: $cursor !important;
        // }
      }
       .el-input__icon{
        font-size: 16px;
      }
    }
    .login_opt{
      display: flex;
      margin-top: 10px;
      margin-bottom: 32px;
    }
    .el-form-item {
      // border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
      margin-bottom: 30px;
    }
    .tips {
      font-size: 14px;
      color: #fff;
      margin-bottom: 10px;
      span {
        &:first-of-type {
          margin-right: 16px;
        }
      }
    }
    .svg-container {
      // padding: 6px 5px 6px 15px;
      // line-height: 50px;
      color: $dark_gray;
      vertical-align: middle;
      width: 25px;
      display: inline-block;
    }
    .title-container {
      position: relative;
      text-align: center;
      margin:10px 0 52px;
      .el-image{
        vertical-align: bottom;
        margin-right: 10px;
      }
      .title {
        display: inline-block;
        font-size: 18px;
        color: #131314;
        line-height: 32px;
        font-family: HarmonyOS Sans SC-Medium, HarmonyOS Sans SC;
        // margin: 0px auto 40px auto;
        text-align: center;
        font-weight: 600;
      }
    }
   .title {
        font-size: 20px;
        color: #131314;
        line-height: 28px;
        font-family: HarmonyOS Sans SC-Medium, HarmonyOS Sans SC;
        text-align: center;
        font-weight: 600;
      }
    .show-pwd {
      font-size: 16px;
      color: $dark_gray;
      cursor: pointer;
      user-select: none;
    }
  }

  .loginbtn{
    width: 100%;
    height: 48px;
    font-size:16px;
  }
  //滑块弹窗
  ::v-deep .slide-dialog{
    overflow-x: hidden;
    .el-dialog{
      margin-right: 190px;
    }
  }
  </style>
